package com.hst.capacity.infra.persistence.jpa.vehicle;

import com.hst.capacity.domain.model.entity.vehicle.VehicleTypeEntity;
import com.hst.capacity.domain.model.response.LabelValueVO;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface VehicleTypeRepository extends CrudRepository<VehicleTypeEntity, String> {

    /**
     * 获取默认车辆类型
     * @return
     */
    @Query("select new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "where t.idVehicleType = 1 ")
    List<LabelValueVO> findDefVehicleType();

    /**
     * 获取全部车辆类型
     * @return
     */
    @Query("select new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t ")
    List<LabelValueVO> findAllVehicleType();

    /**
     * 根据车辆类型查找车辆类型信息
     * @param idVehicleTypes
     * @return
     */
    @Query("select new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "where t.idVehicleType in (?1)")
    List<LabelValueVO> findByIdVehicleTypes(List<Integer> idVehicleTypes);

    /**
     * 根据地区查找开通的快车类型信息
     * @param regionCode
     * @return
     */
    @Query("select distinct new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "inner join SpecialCarPriceEntity p ON p.idVehicleType = t.idVehicleType " +
            "where p.regionCode = :regionCode ")
    List<LabelValueVO> findSpVehicleType(String regionCode);

    /**
     * 根据地区查找开通的快车类型信息
     * @param regionCode
     * @return
     */
    @Query("select distinct new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "inner join ExpressCommonPriceEntity p ON p.idVehicleType = t.idVehicleType " +
            "where p.regionCode = :regionCode ")
    List<LabelValueVO> findExVehicleType(String regionCode);

    /**
     * 根据地区查找开通的快车类型信息(站点接驳)
     * @param regionCode
     * @return
     */
    @Query("select distinct new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "inner join ExpressStpPriceEntity p ON p.idVehicleType = t.idVehicleType " +
            "where p.regionCode = :regionCode ")
    List<LabelValueVO> findCarStationVehicleType(String regionCode);

    /**
     * 根据地区查找开通的快车类型信息(火车接送站)
     * @param idStation
     * @return
     */
    @Query("select distinct new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "inner join RailwayStationPriceEntity p ON p.idVehicleType = t.idVehicleType " +
            "where p.idStation = :idStation ")
    List<LabelValueVO> findRailStationVehicleType(String idStation);

    /**
     * 根据地区查找开通的快车类型信息(接送机)
     * @param idAirport
     * @return
     */
    @Query("select distinct new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "inner join AirportPriceEntity p ON p.idVehicleType = t.idVehicleType " +
            "where p.idAirport = :idAirport ")
    List<LabelValueVO> findAirportVehicleType(String idAirport);

    /**
     * 根据地区查找开通的城际类型信息
     * @param idLine
     * @return
     */
    @Query("select distinct new com.hst.capacity.domain.model.response.vehicle.VehicleTypeVO(t.shortName,t.idVehicleType,t.seats) " +
            "from VehicleTypeEntity t " +
            "inner join IntercityPriceEntity p ON p.idVehicleType = t.idVehicleType " +
            "where p.idLine = :idLine ")
    List<LabelValueVO> findIcVehicleType(String idLine);


    /**
     * 查询被司机绑定的车辆信息
     * @return
     */
    @Query("select vt " +
            "from DriverEntity d " +
            "inner join VehicleEntity v on d.idVehicle = v.idVehicle " +
            "inner join VehicleTypeEntity vt on v.idVehicleType = vt.idVehicleType " +
            "where d.idDriver=?1")
    VehicleTypeEntity findByIdDriver(String idDriver);

    VehicleTypeEntity findByIdVehicleType(int idVehicleType);

}
